package com.macro.mall.tiny.modules.bms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.macro.mall.tiny.modules.bms.dto.StatisticsResult;
import com.macro.mall.tiny.modules.bms.mapper.StatisticsMapper;
import com.macro.mall.tiny.modules.bms.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class StatisticsServiceImpl implements StatisticsService {
    
    @Autowired
    private StatisticsMapper statisticsMapper;
    
    @Override
    public StatisticsResult getStatistics() {
        StatisticsResult result = new StatisticsResult();
        
        // 获取各种统计数量
        result.setProductCount(statisticsMapper.getProductCount());
        result.setOrderCount(statisticsMapper.getOrderCount());
        result.setUserCount(statisticsMapper.getUserCount());
        result.setCartCount(statisticsMapper.getCartCount());
        
        // 获取销售统计数据
        List weeklySales = statisticsMapper.getWeeklySales();
        List monthlySales = statisticsMapper.getMonthlySales();
        
        result.setWeeklySales(weeklySales != null ? weeklySales : Collections.emptyList());
        result.setMonthlySales(monthlySales != null ? monthlySales : Collections.emptyList());
        
        return result;
    }
}